package basic;

import java.util.*;

/**
 * @Author: 海琳琦
 * @Date: 2021/9/7 21:28
 */
public class Title169 {
    public static void main(String[] args) {
        int[] nums = {1,2,2,2,3};
        System.out.println(majorityElement(nums));
    }

    private static int majorityElement(int[] nums) {
        Random random = new Random();
        int length = nums.length / 2;
        int count;
        while(true){
            int num = nums[random.nextInt(nums.length)];
            count = 0;
            for (int i = 0; i < nums.length; i++) {
                if(nums[i]==num){
                    count++;
                }
            }
            if(count>length){
                return num;
            }
        }
    }
}
